/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "zobjects_gtk.h"

#define ZOBJECTS_GTK_OBJECT_DATA_KEY_SOURCEVIEW_SETTINGS	"zobjects_gtk_object_data_key_sourceview_settings"
#define ZOBJECTS_GTK_OBJECT_DATA_KEY_SOURCEVIEW_CONTEXT		"zobjects_gtk_object_data_key_sourceview_context"

#define BLOCK_TEXTBUFFER_SIGNAL_GROUP \
	g_signal_handlers_block_by_func( text_buf , GtkOnSourceViewSelectionChanged , guisourceeditarea_common->gtk_widget ); \

#define UNBLOCK_TEXTBUFFER_SIGNAL_GROUP \
	g_signal_handlers_block_by_func( text_buf , GtkOnSourceViewSelectionChanged , guisourceeditarea_common->gtk_widget ); \

#define FONT_TAG_NAME		"text_view_font"

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_Create_guiwindow;
int ZlangInvokeFunction_guieditarea_Create_guiwindow( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(out1) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;

	EVAL_GTK_WIDGET_NEW_IN_CREATE( guieditarea_common->gtk_widget , gtk_text_view_new() )
	SET_CONTROL_DEFAULT_STYLE( in1 , guieditarea_common->gtk_widget )

	guieditarea_common->gtk_inner = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) ) ;
	gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) , GUIWRAP_WORD_CHAR );

	TRANSFER_INPUT_OBJECT_TO_NEW_OBJECT( guieditarea_common->guiwindow_obj , in1 )

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_SetWrapMode_int;
int ZlangInvokeFunction_guieditarea_SetWrapMode_int( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						wrap_mode ;

	CallRuntimeFunction_int_GetIntValue( rt , in1 , & wrap_mode );

	gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) , wrap_mode );

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_SetFontAndSize_string;
int ZlangInvokeFunction_guieditarea_SetFontAndSize_string( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	char						*font_and_size = NULL ;
	PangoFontDescription				*font_desc = NULL ;
	GtkTextBuffer					*text_buf = NULL ;
	GtkTextTagTable					*tag_table = NULL ;
	GtkTextIter					start_iter , end_iter ;
	GtkTextTag					*tag = NULL ;
	
	CallRuntimeFunction_string_GetStringValue( rt , in1 , & font_and_size , NULL );

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) ) ;

	tag_table = gtk_text_buffer_get_tag_table( text_buf ) ;
	tag = gtk_text_tag_table_lookup(  tag_table , FONT_TAG_NAME );
	if( tag == NULL )
	{
		tag = gtk_text_tag_new( FONT_TAG_NAME ) ;
		gtk_text_tag_table_add( tag_table , tag );
		g_object_unref(tag);
	}
	font_desc = pango_font_description_from_string( font_and_size ) ;
	g_object_set( tag, "font-desc" , font_desc , NULL );
	gtk_text_buffer_get_start_iter( text_buf , & start_iter );
	gtk_text_buffer_get_end_iter( text_buf , & end_iter );
	gtk_text_buffer_remove_tag( text_buf , tag , & start_iter , & end_iter );
	gtk_text_buffer_apply_tag( text_buf , tag , & start_iter , & end_iter );
	pango_font_description_free( font_desc );

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_SetFontAndSize_string_int;
int ZlangInvokeFunction_guieditarea_SetFontAndSize_string_int( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	char						*font = NULL ;
	int32_t						font_size ;
	GtkCssProvider					*provider = NULL ;
	char						css_string[ 256 ] = "" ;

	CallRuntimeFunction_string_GetStringValue( rt , in1 , & font , NULL );
	CallRuntimeFunction_int_GetIntValue( rt , in2 , & font_size );

	provider = gtk_css_provider_new() ;
	snprintf( css_string , sizeof(css_string)-1 , "textview {"
							"   font-family: %s;"
							"   font-size: %dpt;"
							"}" , font , font_size );
	gtk_css_provider_load_from_string( provider , css_string );
	gtk_style_context_add_provider( gtk_widget_get_style_context(guieditarea_common->gtk_widget) , GTK_STYLE_PROVIDER(provider) , GTK_STYLE_PROVIDER_PRIORITY_APPLICATION );

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_SetText_string;
int ZlangInvokeFunction_guieditarea_SetText_string( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	GtkTextBuffer					*text_buf = NULL ;
	char						*str = NULL ;
	GtkTextIter					start_iter ;

	CallRuntimeFunction_string_GetStringValue( rt , in1 , & str , NULL );

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_direct_prop->common.gtk_widget) ) ;
	gtk_text_buffer_set_text( text_buf , str , -1 ) ;
	gtk_text_buffer_get_iter_at_line( text_buf , & start_iter , 0 );
	gtk_text_buffer_place_cursor( text_buf , & start_iter );
	gtk_text_view_scroll_to_iter( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) , & start_iter , 0.0 , TRUE , 0.0 , 0.0 );

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_AppendText_string;
int ZlangInvokeFunction_guieditarea_AppendText_string( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	GtkTextBuffer					*text_buf = NULL ;
	char						*str = NULL ;
	GtkTextIter					end_iter ;

	CallRuntimeFunction_string_GetStringValue( rt , in1 , & str , NULL );

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) ) ;

	gtk_text_buffer_get_end_iter( text_buf , & end_iter );
	gtk_text_buffer_insert( text_buf , & end_iter , str , -1 );

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_AppendText_string_bool;
int ZlangInvokeFunction_guieditarea_AppendText_string_bool( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	GtkTextBuffer					*text_buf = NULL ;
	char						*str = NULL ;
	unsigned char					place_cursor ;
	GtkTextIter					end_iter ;

	CallRuntimeFunction_string_GetStringValue( rt , in1 , & str , NULL );
	CallRuntimeFunction_bool_GetBoolValue( rt , in2 , & place_cursor );

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) ) ;

	gtk_text_buffer_get_end_iter( text_buf , & end_iter );
	gtk_text_buffer_insert( text_buf , & end_iter , str , -1 );

	if( place_cursor == TRUE )
	{
		gtk_text_buffer_place_cursor( text_buf , & end_iter );
		gtk_text_view_scroll_to_iter( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) , & end_iter , 0.0 , TRUE , 0.0 , 0.0 );
	}

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_LoadFile_string;
int ZlangInvokeFunction_guieditarea_LoadFile_string( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	char						*pathfilename = NULL ;
	// char						*filename = NULL ;
	// char						*p = NULL ;
	gchar						*gcontent = NULL ;
	gsize						gcontent_len ;
	GError						*gerror = NULL ;
	gboolean					gb ;
	GtkTextBuffer					*text_buf = NULL ;
	GtkTextIter					start_iter ;

	CallRuntimeFunction_string_GetStringValue( rt , in1 , & pathfilename , NULL );

	gb = g_file_get_contents( pathfilename , & gcontent , & gcontent_len , & gerror );
	if( gb != TRUE )
	{
		TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "g_file_get_contents return error[%d][%s]" , gerror->code,gerror->message )
		g_error_free( gerror );
		UnreferObject( rt , out1 );
		return ThrowErrorException( rt , ZLANG_ERROR_ALLOC , EXCEPTION_MESSAGE_FILE_NOT_FOUND );
	}
	text_buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(guieditarea_common->gtk_widget)) ;
	gtk_text_buffer_set_text( text_buf , gcontent , -1 ) ;
	g_free( gcontent );

	/*
	p = GetFilenamePtr( pathfilename ) ;
	if( p )
		filename = p ;
	else
		filename = pathfilename ;
	*/

	gtk_text_buffer_get_iter_at_line( text_buf , & start_iter , 0 );
	gtk_text_buffer_place_cursor( text_buf , & start_iter );
	gtk_text_view_scroll_to_iter( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) , & start_iter , 0.0 , TRUE , 0.0 , 0.0 );

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_SetCurrentRowNo_int;
int ZlangInvokeFunction_guieditarea_SetCurrentRowNo_int( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						line_no ;
	GtkTextBuffer					*text_buf = NULL ;
	GtkTextIter					jump_iter ;

	CallRuntimeFunction_int_GetIntValue( rt , in1 , & line_no );

	text_buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(guieditarea_common->gtk_widget)) ;

	gtk_text_buffer_get_iter_at_line( text_buf , & jump_iter , line_no-1 );
	gtk_text_buffer_place_cursor( text_buf , & jump_iter );
	gtk_text_view_scroll_to_iter( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) , & jump_iter , 0.0 , TRUE , 0.0 , 0.0 );

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_SetModifiedChangedEventCallback_functionptr;
int ZlangInvokeFunction_guieditarea_SetModifiedChangedEventCallback_functionptr( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	GtkTextBuffer					*text_buf = NULL ;

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_direct_prop->common.gtk_widget) ) ;
	gtk_text_buffer_set_modified( text_buf , FALSE );

	ADD_CONTROL_GENERAL_CALLBACK_IN_CREATE( guieditarea_common->guiwindow_obj , obj , GTK_EVENT_MODIFIED_CHANGED , in1 )

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_SetModified_bool;
int ZlangInvokeFunction_guieditarea_SetModified_bool( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	unsigned char					b ;
	GtkTextBuffer					*text_buf = NULL ;

	CallRuntimeFunction_bool_GetBoolValue( rt , in1 , & b );
	
	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_direct_prop->common.gtk_widget) ) ;
	gtk_text_buffer_set_modified( text_buf , b );

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_SetChangedEventCallback_functionptr;
int ZlangInvokeFunction_guieditarea_SetChangedEventCallback_functionptr( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;

	ADD_CONTROL_GENERAL_CALLBACK_IN_CREATE( guieditarea_common->guiwindow_obj , obj , GTK_EVENT_CHANGED , in1 )

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_SetCursorPositionEventCallback_functionptr;
int ZlangInvokeFunction_guieditarea_SetCursorPositionEventCallback_functionptr( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;

	ADD_CONTROL_NOTIFY_CALLBACK_IN_CREATE( guieditarea_common->guiwindow_obj , obj , GTK_EVENT_NOTIFY_CURSOR_POSITION , in1 )

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_SetHasSelectionEventCallback_functionptr;
int ZlangInvokeFunction_guieditarea_SetHasSelectionEventCallback_functionptr( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;

	ADD_CONTROL_NOTIFY_CALLBACK_IN_CREATE( guieditarea_common->guiwindow_obj , obj , GTK_EVENT_NOTIFY_HAS_SELECTION , in1 )

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZLANG_INVOKE_FUNCTION_guiwidget_all_common_functions( editarea )

ZLANG_INVOKE_FUNCTION_guictl_all_common_functions( editarea )

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_GetCurrentRowNo;
int ZlangInvokeFunction_guieditarea_GetCurrentRowNo( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						row_no ;
	GtkTextBuffer					*text_buf = NULL ;
	GtkTextIter					curr_iter ;

	text_buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(guieditarea_common->gtk_widget)) ;

	gtk_text_buffer_get_iter_at_mark( text_buf , & curr_iter , gtk_text_buffer_get_insert(text_buf) );
	row_no = gtk_text_iter_get_line( & curr_iter ) + 1 ;

	CallRuntimeFunction_int_SetIntValue( rt , out1 , row_no );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_GetCurrentColumnNo;
int ZlangInvokeFunction_guieditarea_GetCurrentColumnNo( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						col_no ;
	GtkTextBuffer					*text_buf = NULL ;
	GtkTextIter					curr_iter ;

	text_buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(guieditarea_common->gtk_widget)) ;

	gtk_text_buffer_get_iter_at_mark( text_buf , & curr_iter , gtk_text_buffer_get_insert(text_buf) );
	col_no = gtk_text_iter_get_line_offset( & curr_iter ) + 1 ;

	CallRuntimeFunction_int_SetIntValue( rt , out1 , col_no );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_GetCurrentFileOffset;
int ZlangInvokeFunction_guieditarea_GetCurrentFileOffset( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						file_offet ;
	GtkTextBuffer					*text_buf = NULL ;
	GtkTextIter					curr_iter ;

	text_buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(guieditarea_common->gtk_widget)) ;

	gtk_text_buffer_get_iter_at_mark( text_buf , & curr_iter , gtk_text_buffer_get_insert(text_buf) );
	file_offet = gtk_text_iter_get_offset( & curr_iter ) ;

	CallRuntimeFunction_int_SetIntValue( rt , out1 , file_offet );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_GetText;
int ZlangInvokeFunction_guieditarea_GetText( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea	*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject			*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	GtkTextBuffer				*text_buf = NULL ;
	GtkTextIter				start_iter , end_iter ;
	char					*str = NULL ;

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_direct_prop->common.gtk_widget) ) ;
	gtk_text_buffer_get_start_iter( text_buf , & start_iter );
	gtk_text_buffer_get_end_iter( text_buf , & end_iter );
	str = gtk_text_buffer_get_text( text_buf , & start_iter , & end_iter , FALSE ) ;
	CallRuntimeFunction_string_SetStringValue( rt , out1 , str , STRLEN_OF_STRING );
	g_free( str );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_GetSelectedText;
int ZlangInvokeFunction_guieditarea_GetSelectedText( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea	*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject			*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	GtkTextBuffer				*text_buf = NULL ;
	GtkTextIter				start_iter , end_iter ;
	char					*selected_text = NULL ;

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_direct_prop->common.gtk_widget) ) ;
	if( gtk_text_buffer_get_selection_bounds( text_buf , & start_iter , & end_iter ) )
	{
		selected_text = gtk_text_buffer_get_text( text_buf , & start_iter , & end_iter , FALSE ) ;
		CallRuntimeFunction_string_SetStringValue( rt , out1 , selected_text , STRLEN_OF_STRING );
		g_free( selected_text );
	}
	else
	{
		UnreferObject( rt , out1 );
	}

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_SaveFile_string;
int ZlangInvokeFunction_guieditarea_SaveFile_string( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	char						*pathfilename = NULL ;
	GtkTextBuffer					*text_buf = NULL ;
	GtkTextIter					start_iter , end_iter ;
	gchar						*file_content = NULL ;
	GError						*gerror = NULL ;
	unsigned char					b ;

	CallRuntimeFunction_string_GetStringValue( rt , in1 , & pathfilename , NULL );

	text_buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(guieditarea_common->gtk_widget)) ;
	gtk_text_buffer_get_start_iter( text_buf , & start_iter );
	gtk_text_buffer_get_end_iter( text_buf , & end_iter );
	file_content = gtk_text_buffer_get_text( text_buf , & start_iter , & end_iter , TRUE ) ;
	b = g_file_set_contents( pathfilename , file_content , -1 , & gerror ) ;
	if( b != TRUE )
	{
		TEST_RUNTIME_DEBUG_THEN_PRINT( rt , "g_file_get_contents return error[%d][%s]" , gerror->code,gerror->message )
		g_error_free( gerror );
		CallRuntimeFunction_bool_SetBoolValue( rt , out1 , FALSE );
		return ThrowErrorException( rt , ZLANG_ERROR_OPEN , EXCEPTION_MESSAGE_OPEN_WRITE_FILE_FAILED );
	}

	gtk_text_buffer_set_modified( text_buf , FALSE );

	CallRuntimeFunction_bool_SetBoolValue( rt , out1 , TRUE );
	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_GetModified;
int ZlangInvokeFunction_guieditarea_GetModified( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	GtkTextBuffer					*text_buf = NULL ;
	unsigned char					b ;

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) ) ;
	b = gtk_text_buffer_get_modified( text_buf ) ;
	CallRuntimeFunction_bool_SetBoolValue( rt , out1 , b );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_Undo;
int ZlangInvokeFunction_guieditarea_Undo( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	GtkTextBuffer					*text_buf = NULL ;

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) ) ;
	gtk_text_buffer_undo( text_buf );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_Redo;
int ZlangInvokeFunction_guieditarea_Redo( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	GtkTextBuffer					*text_buf = NULL ;

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) ) ;
	gtk_text_buffer_redo( text_buf );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_Cut;
int ZlangInvokeFunction_guieditarea_Cut( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	GtkTextBuffer					*text_buf = NULL ;
	GtkTextIter					start , end ;
	gboolean					has_selection ;

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW( guieditarea_common->gtk_widget ) ) ;
	has_selection = gtk_text_buffer_get_selection_bounds( text_buf , & start , & end ) ;
	if( has_selection )
	{
		gtk_text_buffer_cut_clipboard( text_buf , gtk_widget_get_clipboard(guieditarea_common->gtk_widget) , TRUE );
	}

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_Copy;
int ZlangInvokeFunction_guieditarea_Copy( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	GtkTextBuffer					*text_buf = NULL ;
	GtkTextIter					start , end ;
	gboolean					has_selection ;

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW( guieditarea_common->gtk_widget ) ) ;
	has_selection = gtk_text_buffer_get_selection_bounds( text_buf , & start , & end ) ;
	if( has_selection )
	{
		gtk_text_buffer_copy_clipboard( text_buf , gtk_widget_get_clipboard(guieditarea_common->gtk_widget) );
	}

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_Paste;
int ZlangInvokeFunction_guieditarea_Paste( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	GtkTextBuffer					*text_buf = NULL ;

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW( guieditarea_common->gtk_widget ) ) ;
	gtk_text_buffer_paste_clipboard( text_buf , gtk_widget_get_clipboard(guieditarea_common->gtk_widget) , NULL , TRUE );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_Delete;
int ZlangInvokeFunction_guieditarea_Delete( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	GtkTextBuffer					*text_buf = NULL ;
	GtkTextIter					start , end ;
	gboolean					has_selection ;

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW( guieditarea_common->gtk_widget ) ) ;
	has_selection = gtk_text_buffer_get_selection_bounds( text_buf , & start , & end ) ;
	if( has_selection )
	{
		gtk_text_buffer_delete_selection( text_buf , TRUE , TRUE );
	}

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_MoveLeftWord;
int ZlangInvokeFunction_guieditarea_MoveLeftWord( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	GtkTextBuffer					*text_buf = NULL ;
	GtkTextMark					*curr_pos_mark = NULL ;
	GtkTextIter					curr_pos_iter ;

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) ) ;

	curr_pos_mark = gtk_text_buffer_get_insert( text_buf ) ;
	gtk_text_buffer_get_iter_at_mark( text_buf , & curr_pos_iter , curr_pos_mark );
	gtk_text_iter_backward_word_start( & curr_pos_iter );
	gtk_text_buffer_place_cursor( text_buf , & curr_pos_iter );
	gtk_text_view_scroll_to_iter( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) , & curr_pos_iter , 0.1 , FALSE , 0.0 , 0.0 );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_MoveRightWord;
int ZlangInvokeFunction_guieditarea_MoveRightWord( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	GtkTextBuffer					*text_buf = NULL ;
	GtkTextMark					*curr_pos_mark = NULL ;
	GtkTextIter					curr_pos_iter ;

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) ) ;

	curr_pos_mark = gtk_text_buffer_get_insert( text_buf ) ;
	gtk_text_buffer_get_iter_at_mark( text_buf , & curr_pos_iter , curr_pos_mark );
	gtk_text_iter_forward_word_end( & curr_pos_iter );
	gtk_text_buffer_place_cursor( text_buf , & curr_pos_iter );
	gtk_text_view_scroll_to_iter( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) , & curr_pos_iter , 0.1 , FALSE , 0.0 , 0.0 );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_SelectAll;
int ZlangInvokeFunction_guieditarea_SelectAll( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	GtkTextBuffer					*text_buf = NULL ;
	GtkTextIter					all_selected_start , all_selected_end ;

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) ) ;

	gtk_text_buffer_get_start_iter( text_buf , & all_selected_start );
	gtk_text_buffer_get_end_iter( text_buf , & all_selected_end );
	gtk_text_buffer_select_range( text_buf , & all_selected_start , & all_selected_end );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_SelectWord;
int ZlangInvokeFunction_guieditarea_SelectWord( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	GtkTextBuffer					*text_buf = NULL ;
	GtkTextMark					*curr_pos_mark = NULL ;
	GtkTextIter					curr_pos_iter ;
	GtkTextIter					word_start_selected_iter , word_end_selected_iter ;

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) ) ;

	curr_pos_mark = gtk_text_buffer_get_insert( text_buf ) ;
	gtk_text_buffer_get_iter_at_mark( text_buf , & curr_pos_iter , curr_pos_mark );
	if( ! gtk_text_iter_inside_word( & curr_pos_iter ) )
		return 0;
	word_start_selected_iter = word_end_selected_iter = curr_pos_iter ;
	if( ! gtk_text_iter_starts_word( & word_start_selected_iter ) )
		gtk_text_iter_backward_word_start( & word_start_selected_iter );
	if( ! gtk_text_iter_ends_word( & word_end_selected_iter ) )
		gtk_text_iter_forward_word_end( & word_end_selected_iter );
	gtk_text_buffer_select_range( text_buf , & word_start_selected_iter , & word_end_selected_iter );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_SelectLine;
int ZlangInvokeFunction_guieditarea_SelectLine( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	GtkTextBuffer					*text_buf = NULL ;
	GtkTextMark					*curr_pos_mark = NULL ;
	GtkTextIter					curr_pos_iter ;
	GtkTextIter					line_start_selected_iter , line_end_selected_iter ;

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) ) ;

	curr_pos_mark = gtk_text_buffer_get_insert( text_buf ) ;
	gtk_text_buffer_get_iter_at_mark( text_buf , & curr_pos_iter , curr_pos_mark );
	line_start_selected_iter = line_end_selected_iter = curr_pos_iter ;
	gtk_text_iter_set_line_offset( & line_start_selected_iter , 0 );
	gtk_text_iter_forward_line( & line_end_selected_iter );
	gtk_text_buffer_select_range( text_buf , & line_start_selected_iter , & line_end_selected_iter );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_AppendSelectLeftWord;
int ZlangInvokeFunction_guieditarea_AppendSelectLeftWord( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	GtkTextBuffer					*text_buf = NULL ;
	GtkTextMark					*curr_pos_mark = NULL ;
	GtkTextIter					curr_pos_iter ;
	GtkTextIter					start_selected_iter , end_selected_iter ;

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) ) ;

	if( ! gtk_text_buffer_get_selection_bounds( text_buf , & start_selected_iter , & end_selected_iter ) )
	{
		curr_pos_mark = gtk_text_buffer_get_insert( text_buf ) ;
		gtk_text_buffer_get_iter_at_mark( text_buf , & curr_pos_iter , curr_pos_mark );
		if( ! gtk_text_iter_inside_word( & curr_pos_iter ) )
			return 0;
		start_selected_iter = end_selected_iter = curr_pos_iter ;
		if( ! gtk_text_iter_starts_word( & start_selected_iter ) )
			gtk_text_iter_backward_word_start( & start_selected_iter );
		gtk_text_buffer_select_range( text_buf , & start_selected_iter , & end_selected_iter );
	}
	else
	{
		gtk_text_iter_backward_word_start( & start_selected_iter );
		gtk_text_buffer_select_range( text_buf , & start_selected_iter , & end_selected_iter );
	}

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_AppendSelectRightWord;
int ZlangInvokeFunction_guieditarea_AppendSelectRightWord( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	GtkTextBuffer					*text_buf = NULL ;
	GtkTextMark					*curr_pos_mark = NULL ;
	GtkTextIter					curr_pos_iter ;
	GtkTextIter					start_selected_iter , end_selected_iter ;

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) ) ;

	if( ! gtk_text_buffer_get_selection_bounds( text_buf , & start_selected_iter , & end_selected_iter ) )
	{
		curr_pos_mark = gtk_text_buffer_get_insert( text_buf ) ;
		gtk_text_buffer_get_iter_at_mark( text_buf , & curr_pos_iter , curr_pos_mark );
		if( ! gtk_text_iter_inside_word( & curr_pos_iter ) )
			return 0;
		start_selected_iter = end_selected_iter = curr_pos_iter ;
		if( ! gtk_text_iter_ends_word( & end_selected_iter ) )
			gtk_text_iter_forward_word_end( & end_selected_iter );
		gtk_text_buffer_select_range( text_buf , & start_selected_iter , & end_selected_iter );
	}
	else
	{
		gtk_text_iter_forward_word_end( & end_selected_iter );
		gtk_text_buffer_select_range( text_buf , & start_selected_iter , & end_selected_iter );
	}

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_GotoLine_int;
int ZlangInvokeFunction_guieditarea_GotoLine_int( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	GtkTextBuffer					*text_buf = NULL ;
	int32_t						line_no ;
	GtkTextIter					goto_iter ;

	CallRuntimeFunction_int_GetIntValue( rt , in1 , & line_no );

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) ) ;

	gtk_text_buffer_get_iter_at_line( text_buf , & goto_iter , line_no-1 );
	gtk_text_buffer_place_cursor( text_buf , & goto_iter );
	gtk_text_view_scroll_to_iter( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) , & goto_iter , 0.0 , TRUE , 0.0 , 0.0 );
	gtk_widget_grab_focus( guieditarea_common->gtk_widget );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_GotoFileOffset_int;
int ZlangInvokeFunction_guieditarea_GotoFileOffset_int( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	GtkTextBuffer					*text_buf = NULL ;
	int32_t						file_offset_no ;
	GtkTextIter					goto_iter ;

	CallRuntimeFunction_int_GetIntValue( rt , in1 , & file_offset_no );

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) ) ;

	gtk_text_buffer_get_iter_at_offset( text_buf , & goto_iter , file_offset_no-1 );
	gtk_text_buffer_place_cursor( text_buf , & goto_iter );
	gtk_text_view_scroll_to_iter( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) , & goto_iter , 0.0 , TRUE , 0.0 , 0.0 );
	gtk_widget_grab_focus( guieditarea_common->gtk_widget );

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guieditarea_GotoLineOffset_int;
int ZlangInvokeFunction_guieditarea_GotoLineOffset_int( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = & (guieditarea_direct_prop->common) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	GtkTextBuffer					*text_buf = NULL ;
	GtkTextMark					*curr_pos_mark = NULL ;
	GtkTextIter					curr_pos_iter ;
	int						curr_line_no ;
	int32_t						curr_line_offest_no ;
	GtkTextIter					goto_iter ;

	CallRuntimeFunction_int_GetIntValue( rt , in1 , & curr_line_offest_no );

	text_buf = gtk_text_view_get_buffer( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) ) ;

	curr_pos_mark = gtk_text_buffer_get_insert( text_buf ) ;
	gtk_text_buffer_get_iter_at_mark( text_buf , & curr_pos_iter , curr_pos_mark );
	curr_line_no = gtk_text_iter_get_line( & curr_pos_iter ) ;
	gtk_text_buffer_get_iter_at_line_offset( text_buf , & goto_iter , curr_line_no , curr_line_offest_no-1 );
	gtk_text_buffer_place_cursor( text_buf , & goto_iter );
	gtk_text_view_scroll_to_iter( GTK_TEXT_VIEW(guieditarea_common->gtk_widget) , & goto_iter , 0.0 , TRUE , 0.0 , 0.0 );
	gtk_widget_grab_focus( guieditarea_common->gtk_widget );

	return 0;
}

ZlangCreateDirectPropertyFunction ZlangCreateDirectProperty_guieditarea;
void *ZlangCreateDirectProperty_guieditarea( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea		*guieditarea_prop = NULL ;
	struct ZlangDirectProperty_guiwidget_common	*guieditarea_common = NULL ;
	
	guieditarea_prop = (struct ZlangDirectProperty_guieditarea *)ZLMALLOC( sizeof(struct ZlangDirectProperty_guieditarea) ) ;
	if( guieditarea_prop == NULL )
	{
		SET_RUNTIME_ERROR( rt , RUNTIME_ERROR , ZLANG_ERROR_ALLOC , "alloc memory for entity" )
		return NULL;
	}
	memset( guieditarea_prop , 0x00 , sizeof(struct ZlangDirectProperty_guieditarea) );

	guieditarea_common = (struct ZlangDirectProperty_guiwidget_common *)guieditarea_prop ;
	guieditarea_common->gtk_widget_type_id = GTK_TYPE_TEXT_VIEW ;

	INIT_ZLANGDIRECTPROPERTY_guiwidget_common(guieditarea)
	
	return guieditarea_prop;
}

ZlangDestroyDirectPropertyFunction ZlangDestroyDirectProperty_guieditarea;
void ZlangDestroyDirectProperty_guieditarea( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guieditarea	*guieditarea_direct_prop = GetObjectDirectProperty(obj) ;
	
	CLEAN_ZLANGDIRECTPROPERTY_guiwidget_common(guieditarea)

	ZLFREE( guieditarea_direct_prop );
	
	return;
}

ZlangSummarizeDirectPropertySizeFunction ZlangSummarizeDirectPropertySize_guieditarea;
void ZlangSummarizeDirectPropertySize_guieditarea( struct ZlangRuntime *rt , struct ZlangObject *obj , size_t *summarized_obj_size , size_t *summarized_direct_prop_size )
{
	SUMMARIZE_SIZE( summarized_direct_prop_size , sizeof(struct ZlangDirectProperty_guieditarea) )
	return;
}

static struct ZlangDirectFunctions direct_funcs_guieditarea =
	{
		ZLANG_OBJECT_guieditarea , /* char *ancestor_name */
		
		ZlangCreateDirectProperty_guieditarea , /* ZlangCreateDirectPropertyFunction *create_entity_func */
		ZlangDestroyDirectProperty_guieditarea , /* ZlangDestroyDirectPropertyFunction *destroy_entity_func */
		
		NULL , /* ZlangFromCharPtrFunction *from_char_ptr_func */
		NULL , /* ZlangToStringFunction *to_string_func */
		NULL , /* ZlangFromDataPtrFunction *from_data_ptr_func */
		NULL , /* ZlangGetDataPtrFunction *get_data_ptr_func */
		
		NULL , /* ZlangOperatorFunction *oper_PLUS_func */
		NULL , /* ZlangOperatorFunction *oper_MINUS_func */
		NULL , /* ZlangOperatorFunction *oper_MUL_func */
		NULL , /* ZlangOperatorFunction *oper_DIV_func */
		NULL , /* ZlangOperatorFunction *oper_MOD_func */
		
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_NEGATIVE_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_NOT_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_BIT_REVERSE_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_PLUS_PLUS_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_MINUS_MINUS_func */
		
		NULL , /* ZlangCompareFunction *comp_EGUAL_func */
		NULL , /* ZlangCompareFunction *comp_NOTEGUAL_func */
		NULL , /* ZlangCompareFunction *comp_LT_func */
		NULL , /* ZlangCompareFunction *comp_LE_func */
		NULL , /* ZlangCompareFunction *comp_GT_func */
		NULL , /* ZlangCompareFunction *comp_GE_func */
		
		NULL , /* ZlangLogicFunction *logic_AND_func */
		NULL , /* ZlangLogicFunction *logic_OR_func */
		
		NULL , /* ZlangLogicFunction *bit_AND_func */
		NULL , /* ZlangLogicFunction *bit_XOR_func */
		NULL , /* ZlangLogicFunction *bit_OR_func */
		NULL , /* ZlangLogicFunction *bit_MOVELEFT_func */
		NULL , /* ZlangLogicFunction *bit_MOVERIGHT_func */
		
		ZlangSummarizeDirectPropertySize_guieditarea , /* ZlangSummarizeDirectPropertySizeFunction *summarize_direct_prop_size_func */
	} ;

ZlangImportObjectFunction ZlangImportObject_guieditarea;
struct ZlangObject *ZlangImportObject_guieditarea( struct ZlangRuntime *rt )
{
	struct ZlangObject	*obj = NULL ;
	struct ZlangObject	*prop = NULL ;
	struct ZlangFunction	*func = NULL ;
	int			nret = 0 ;
	
	nret = ImportObject( rt , & obj , ZLANG_OBJECT_guieditarea , & direct_funcs_guieditarea , sizeof(struct ZlangDirectFunctions) , NULL ) ;
	if( nret )
	{
		SET_RUNTIME_ERROR( rt , RUNTIME_ERROR , ZLANG_ERROR_LINK_FUNC_TO_ENTITY , "import object to global objects heap" )
		return NULL;
	}
	
	prop = AddPropertyInObject( rt , obj , GetIntObjectInRuntimeObjectsHeap(rt) , "WRAP_NONE") ;
	if( prop == NULL )
		return NULL;
	CallRuntimeFunction_int_SetIntValue( rt , prop , GUIWRAP_NONE );
	SetConstantObject( prop );
	
	prop = AddPropertyInObject( rt , obj , GetIntObjectInRuntimeObjectsHeap(rt) , "WRAP_CHAR") ;
	if( prop == NULL )
		return NULL;
	CallRuntimeFunction_int_SetIntValue( rt , prop , GUIWRAP_CHAR );
	SetConstantObject( prop );
	
	prop = AddPropertyInObject( rt , obj , GetIntObjectInRuntimeObjectsHeap(rt) , "WRAP_WORD") ;
	if( prop == NULL )
		return NULL;
	CallRuntimeFunction_int_SetIntValue( rt , prop , GUIWRAP_WORD );
	SetConstantObject( prop );
	
	prop = AddPropertyInObject( rt , obj , GetIntObjectInRuntimeObjectsHeap(rt) , "WRAP_WORD_CHAR") ;
	if( prop == NULL )
		return NULL;
	CallRuntimeFunction_int_SetIntValue( rt , prop , GUIWRAP_WORD_CHAR );
	SetConstantObject( prop );
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_Create_guiwindow , ZLANG_OBJECT_guieditarea , "Create" , ZLANG_OBJECT_guiwindow,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_SetWrapMode_int , ZLANG_OBJECT_guieditarea , "SetWrapMode" , ZLANG_OBJECT_int,NULL , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_SetFontAndSize_string , ZLANG_OBJECT_guieditarea , "SetFontAndSize" , ZLANG_OBJECT_string,NULL , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_SetFontAndSize_string_int , ZLANG_OBJECT_guieditarea , "SetFontAndSize" , ZLANG_OBJECT_string,NULL , ZLANG_OBJECT_int,NULL , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_SetText_string , ZLANG_OBJECT_guieditarea , "SetText" , ZLANG_OBJECT_string,NULL , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_AppendText_string , ZLANG_OBJECT_guieditarea , "AppendText" , ZLANG_OBJECT_string,NULL , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_AppendText_string_bool , ZLANG_OBJECT_guieditarea , "AppendText" , ZLANG_OBJECT_string,NULL , ZLANG_OBJECT_bool,NULL , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_LoadFile_string , ZLANG_OBJECT_guieditarea , "LoadFile" , ZLANG_OBJECT_string,NULL , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_SetCurrentRowNo_int , ZLANG_OBJECT_guieditarea , "SetCurrentRowNo" , ZLANG_OBJECT_int,NULL , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_SetModifiedChangedEventCallback_functionptr , ZLANG_OBJECT_guieditarea , "SetModifiedChangedEventCallback" , ZLANG_OBJECT_functionptr,NULL , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_SetModified_bool , ZLANG_OBJECT_guieditarea , "SetModified" , ZLANG_OBJECT_bool,NULL , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_SetChangedEventCallback_functionptr , ZLANG_OBJECT_guieditarea , "SetChangedEventCallback" , ZLANG_OBJECT_functionptr,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_SetCursorPositionEventCallback_functionptr , ZLANG_OBJECT_guieditarea , "SetCursorPositionEventCallback" , ZLANG_OBJECT_functionptr,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_SetHasSelectionEventCallback_functionptr , ZLANG_OBJECT_guieditarea , "SetHasSelectionEventCallback" , ZLANG_OBJECT_functionptr,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	ADD_FUNCTION_AND_PARAMETERS_IN_OBJECT_guiwidget_all_common_functions( editarea )

	ADD_FUNCTION_AND_PARAMETERS_IN_OBJECT_guictl_all_common_functions( editarea )

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_GetCurrentRowNo , ZLANG_OBJECT_int , "GetCurrentRowNo" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_GetCurrentColumnNo , ZLANG_OBJECT_int , "GetCurrentColumnNo" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_GetCurrentFileOffset , ZLANG_OBJECT_int , "GetCurrentFileOffset" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_GetText , ZLANG_OBJECT_string , "GetText" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_GetSelectedText , ZLANG_OBJECT_string , "GetSelectedText" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_SaveFile_string , ZLANG_OBJECT_bool , "SaveFile" , ZLANG_OBJECT_string,NULL , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_GetModified , ZLANG_OBJECT_bool , "GetModified" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_Undo , ZLANG_OBJECT_void , "Undo" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_Redo , ZLANG_OBJECT_void , "Redo" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_Cut , ZLANG_OBJECT_void , "Cut" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_Copy , ZLANG_OBJECT_void , "Copy" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_Paste , ZLANG_OBJECT_void , "Paste" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_Delete , ZLANG_OBJECT_void , "Delete" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_MoveLeftWord , ZLANG_OBJECT_void , "MoveLeftWord" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_MoveRightWord , ZLANG_OBJECT_void , "MoveRightWord" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_SelectAll , ZLANG_OBJECT_void , "SelectAll" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_SelectWord , ZLANG_OBJECT_void , "SelectWord" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_SelectLine , ZLANG_OBJECT_void , "SelectLine" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_AppendSelectLeftWord , ZLANG_OBJECT_void , "AppendSelectLeftWord" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_AppendSelectRightWord , ZLANG_OBJECT_void , "AppendSelectRightWord" , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_GotoLine_int , ZLANG_OBJECT_void , "GotoLine" , ZLANG_OBJECT_int,NULL , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_GotoFileOffset_int , ZLANG_OBJECT_void , "GotoFileOffset" , ZLANG_OBJECT_int,NULL , NULL ) ;
	if( func == NULL )
		return NULL;

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guieditarea_GotoLineOffset_int , ZLANG_OBJECT_void , "GotoLineOffset" , ZLANG_OBJECT_int,NULL , NULL ) ;
	if( func == NULL )
		return NULL;

	return obj ;
}

